<?php

namespace App\Models;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class BaseModel extends Model
{
    use HasFactory;

    /**
     * @param DateTimeInterface $date
     * @return string
     * 重写模型的serializeDate方法
     * "created_at": "2022-05-11T14:31:02.000000Z", 格式变为 "created_at": "2022-05-11 14:45:25",
     */
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

}
